\doxysection{C\+:/\+Users/\+ASUS/\+Desktop/dm-\/ctrl\+H7-\/balance-\/9025test/bsp/usart/bsp\+\_\+usart.c File Reference}
\hypertarget{bsp__usart_8c}{}\label{bsp__usart_8c}\index{C:/Users/ASUS/Desktop/dm-\/ctrlH7-\/balance-\/9025test/bsp/usart/bsp\_usart.c@{C:/Users/ASUS/Desktop/dm-\/ctrlH7-\/balance-\/9025test/bsp/usart/bsp\_usart.c}}


串口bsp层的实现  


{\ttfamily \#include "{}bsp\+\_\+usart.\+h"{}}\newline
{\ttfamily \#include "{}bsp\+\_\+log.\+h"{}}\newline
{\ttfamily \#include "{}stdlib.\+h"{}}\newline
{\ttfamily \#include "{}memory.\+h"{}}\newline
\doxysubsubsection*{Functions}
\begin{DoxyCompactItemize}
\item 
void \mbox{\hyperlink{bsp__usart_8c_ac45bba3591501c066f505a46dbae7e2b}{USARTService\+Init}} (\mbox{\hyperlink{struct_u_s_a_r_t_instance}{USARTInstance}} \texorpdfstring{$\ast$}{*}\+\_\+instance)
\begin{DoxyCompactList}\small\item\em 启动串口服务,会在每个实例注册之后自动启用接收,当前实现为\+DMA接收,后续可能添加\+IT和\+BLOCKING接收 \end{DoxyCompactList}\item 
\mbox{\hyperlink{struct_u_s_a_r_t_instance}{USARTInstance}} \texorpdfstring{$\ast$}{*} \mbox{\hyperlink{bsp__usart_8c_a4296c218240b51944ecb698eed2625ef}{USARTRegister}} (\mbox{\hyperlink{struct_u_s_a_r_t___init___config__s}{USART\+\_\+\+Init\+\_\+\+Config\+\_\+s}} \texorpdfstring{$\ast$}{*}init\+\_\+config)
\begin{DoxyCompactList}\small\item\em 注册一个串口实例,返回一个串口实例指针 \end{DoxyCompactList}\item 
void \mbox{\hyperlink{bsp__usart_8c_a12acc10fbb458df894b53534ae66c25d}{USARTSend}} (\mbox{\hyperlink{struct_u_s_a_r_t_instance}{USARTInstance}} \texorpdfstring{$\ast$}{*}\+\_\+instance, uint8\+\_\+t \texorpdfstring{$\ast$}{*}send\+\_\+buf, uint16\+\_\+t send\+\_\+size, USART\+\_\+\+TRANSFER\+\_\+\+MODE mode)
\begin{DoxyCompactList}\small\item\em 通过调用该函数可以发送一帧数据,需要传入一个usart实例,发送buff以及这一帧的长度 \end{DoxyCompactList}\item 
uint8\+\_\+t \mbox{\hyperlink{bsp__usart_8c_a4a4a562d3a505abe103d09f65ef860e4}{USARTIs\+Ready}} (\mbox{\hyperlink{struct_u_s_a_r_t_instance}{USARTInstance}} \texorpdfstring{$\ast$}{*}\+\_\+instance)
\begin{DoxyCompactList}\small\item\em 判断串口是否准备好,用于连续或异步的\+IT/\+DMA发送 \end{DoxyCompactList}\item 
void \mbox{\hyperlink{group___u_a_r_t___exported___functions___group2_ga925534fb8bf7ca464fd05c982fe4bfa0}{HAL\+\_\+\+UARTEx\+\_\+\+Rx\+Event\+Callback}} (\mbox{\hyperlink{group___u_a_r_t___exported___types_ga5de4a49eb132735325e706f406c69d6e}{UART\+\_\+\+Handle\+Type\+Def}} \texorpdfstring{$\ast$}{*}huart, uint16\+\_\+t Size)
\begin{DoxyCompactList}\small\item\em 每次dma/idle中断发生时，都会调用此函数.对于每个uart实例会调用对应的回调进行进一步的处理 例如\+:视觉协议解析/遥控器解析/裁判系统解析 \end{DoxyCompactList}\item 
void \mbox{\hyperlink{group___u_a_r_t___exported___functions___group2_ga0e0456ea96d55db31de947fb3e954f18}{HAL\+\_\+\+UART\+\_\+\+Error\+Callback}} (\mbox{\hyperlink{group___u_a_r_t___exported___types_ga5de4a49eb132735325e706f406c69d6e}{UART\+\_\+\+Handle\+Type\+Def}} \texorpdfstring{$\ast$}{*}huart)
\begin{DoxyCompactList}\small\item\em 当串口发送/接收出现错误时,会调用此函数,此时这个函数要做的就是重新启动接收 \end{DoxyCompactList}\end{DoxyCompactItemize}


\doxysubsection{Detailed Description}
串口bsp层的实现 

\begin{DoxyAuthor}{Author}
neozng 
\end{DoxyAuthor}
\begin{DoxyVersion}{Version}
beta 
\end{DoxyVersion}
\begin{DoxyDate}{Date}
2022-\/11-\/01
\end{DoxyDate}
\begin{DoxyCopyright}{Copyright}
Copyright (c) 2022 
\end{DoxyCopyright}


\label{doc-func-members}
\Hypertarget{bsp__usart_8c_doc-func-members}
\doxysubsection{Function Documentation}
\Hypertarget{bsp__usart_8c_a4a4a562d3a505abe103d09f65ef860e4}\index{bsp\_usart.c@{bsp\_usart.c}!USARTIsReady@{USARTIsReady}}
\index{USARTIsReady@{USARTIsReady}!bsp\_usart.c@{bsp\_usart.c}}
\doxysubsubsection{\texorpdfstring{USARTIsReady()}{USARTIsReady()}}
{\footnotesize\ttfamily \label{bsp__usart_8c_a4a4a562d3a505abe103d09f65ef860e4} 
uint8\+\_\+t USARTIs\+Ready (\begin{DoxyParamCaption}\item[{\mbox{\hyperlink{struct_u_s_a_r_t_instance}{USARTInstance}} \texorpdfstring{$\ast$}{*}}]{\+\_\+instance}{}\end{DoxyParamCaption})}



判断串口是否准备好,用于连续或异步的\+IT/\+DMA发送 


\begin{DoxyParams}{Parameters}
{\em \+\_\+instance} & 要判断的串口实例 \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
uint8\+\_\+t ready 1, busy 0 
\end{DoxyReturn}
\Hypertarget{bsp__usart_8c_a4296c218240b51944ecb698eed2625ef}\index{bsp\_usart.c@{bsp\_usart.c}!USARTRegister@{USARTRegister}}
\index{USARTRegister@{USARTRegister}!bsp\_usart.c@{bsp\_usart.c}}
\doxysubsubsection{\texorpdfstring{USARTRegister()}{USARTRegister()}}
{\footnotesize\ttfamily \label{bsp__usart_8c_a4296c218240b51944ecb698eed2625ef} 
\mbox{\hyperlink{struct_u_s_a_r_t_instance}{USARTInstance}} \texorpdfstring{$\ast$}{*} USARTRegister (\begin{DoxyParamCaption}\item[{\mbox{\hyperlink{struct_u_s_a_r_t___init___config__s}{USART\+\_\+\+Init\+\_\+\+Config\+\_\+s}} \texorpdfstring{$\ast$}{*}}]{init\+\_\+config}{}\end{DoxyParamCaption})}



注册一个串口实例,返回一个串口实例指针 


\begin{DoxyParams}{Parameters}
{\em init\+\_\+config} & 传入串口初始化结构体 \\
\hline
\end{DoxyParams}
\Hypertarget{bsp__usart_8c_a12acc10fbb458df894b53534ae66c25d}\index{bsp\_usart.c@{bsp\_usart.c}!USARTSend@{USARTSend}}
\index{USARTSend@{USARTSend}!bsp\_usart.c@{bsp\_usart.c}}
\doxysubsubsection{\texorpdfstring{USARTSend()}{USARTSend()}}
{\footnotesize\ttfamily \label{bsp__usart_8c_a12acc10fbb458df894b53534ae66c25d} 
void USARTSend (\begin{DoxyParamCaption}\item[{\mbox{\hyperlink{struct_u_s_a_r_t_instance}{USARTInstance}} \texorpdfstring{$\ast$}{*}}]{\+\_\+instance}{, }\item[{uint8\+\_\+t \texorpdfstring{$\ast$}{*}}]{send\+\_\+buf}{, }\item[{uint16\+\_\+t}]{send\+\_\+size}{, }\item[{USART\+\_\+\+TRANSFER\+\_\+\+MODE}]{mode}{}\end{DoxyParamCaption})}



通过调用该函数可以发送一帧数据,需要传入一个usart实例,发送buff以及这一帧的长度 

\begin{DoxyNote}{Note}
在短时间内连续调用此接口,若采用\+IT/\+DMA会导致上一次的发送未完成而新的发送取消. 

若希望连续使用\+DMA/\+IT进行发送,请配合\+USARTIs\+Ready()使用,或自行为你的module实现一个发送队列和任务. 
\end{DoxyNote}
\begin{DoxyRefDesc}{Todo}
\item[\mbox{\hyperlink{todo__todo000006}{Todo}}]是否考虑为\+USARTInstance增加发送队列以进行连续发送?\end{DoxyRefDesc}



\begin{DoxyParams}{Parameters}
{\em \+\_\+instance} & 串口实例 \\
\hline
{\em send\+\_\+buf} & 待发送数据的buffer \\
\hline
{\em send\+\_\+size} & how many bytes to send \\
\hline
\end{DoxyParams}
\Hypertarget{bsp__usart_8c_ac45bba3591501c066f505a46dbae7e2b}\index{bsp\_usart.c@{bsp\_usart.c}!USARTServiceInit@{USARTServiceInit}}
\index{USARTServiceInit@{USARTServiceInit}!bsp\_usart.c@{bsp\_usart.c}}
\doxysubsubsection{\texorpdfstring{USARTServiceInit()}{USARTServiceInit()}}
{\footnotesize\ttfamily \label{bsp__usart_8c_ac45bba3591501c066f505a46dbae7e2b} 
void USARTService\+Init (\begin{DoxyParamCaption}\item[{\mbox{\hyperlink{struct_u_s_a_r_t_instance}{USARTInstance}} \texorpdfstring{$\ast$}{*}}]{\+\_\+instance}{}\end{DoxyParamCaption})}



启动串口服务,会在每个实例注册之后自动启用接收,当前实现为\+DMA接收,后续可能添加\+IT和\+BLOCKING接收 

启动串口服务,需要传入一个usart实例.\+一般用于lost callback的情况(使用串口的模块daemon)

\begin{DoxyRefDesc}{Todo}
\item[\mbox{\hyperlink{todo__todo000005}{Todo}}]串口服务会在每个实例注册之后自动启用接收,当前实现为\+DMA接收,后续可能添加\+IT和\+BLOCKING接收 可能还要将此函数修改为extern,使得module可以控制串口的启停\end{DoxyRefDesc}



\begin{DoxyParams}{Parameters}
{\em \+\_\+instance} & instance owned by module,模块拥有的串口实例 \\
\hline
\end{DoxyParams}
